<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>userList</title>
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}"></link>
    <script type="text/javascript" th:src="@{/js/My97DatePicker/WdatePicker.js}"></script>
    <script type="text/javascript" src="/js/My97DatePicker/lang/zh-cn.js"></script>
    <script type="text/javascript" th:src="@{/js/jquery/jquery-1.10.2.min.js}"></script>
</head>
<body class="container">
<br/>
<h1>账单列表</h1>
<br/><br/>
<div class="with:80%">
    <form class="form-inline" id="qf"  th:action="@{/bill/list-page}"  method="post">
		<input type="hidden" id="page-num-input" name="pageNum" th:value="${pageNum}">
        <input type="hidden" id="page-size-input" name="size" th:value="${size}">

        <div class="form-group">
            <label for="typeId" class="control-label">类型</label>
            <select name="typeId" id="typeId" class="form-control">
                <option value="-1">全部</option>
                <option th:each="type : ${billTypes}" th:value="${type.id}" th:text="${type.name}" th:selected="${type.id==typeId?'true':'false'}"></option>
            </select>
        </div>
        <div class="form-group">
            <label for="date1" class="control-label" >开始时间</label>
            <input type="text" class="form-control" name="fromDate" id="date1" placeholder="开始时间" th:value="${fromDate}" onclick="WdatePicker()"/>
        </div>
        <div class="form-group">
            <label for="date2" class="control-label">结束时间</label>
            <input type="text" class="form-control" name="toDate"  id="date2" placeholder="结束时间" th:value="${toDate}" onclick="WdatePicker()"/>
        </div>
        <div class="form-group">
            <input type="submit" value="查询" class="btn btn-info" />
            &nbsp; &nbsp;
            <input type="reset" value="重置" class="btn btn-info" />
            &nbsp; &nbsp;
            <a href="/bill/toAdd" th:href="@{/bill/toAdd}" class="btn btn-info">添加</a>
        </div>
    </form>
</div>
<br/>

<div class="with:80%">
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>编号</th>
                <th>标题</th>
                <th>时间</th>
                <th>金额</th>
                <th>类别</th>
                <th>说明</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <tr th:each="bill, status : ${bills}">
                <th th:text="${status.count + size * (pageNum - 1)}">-</th>
                <th th:text="${bill.title}">-</th>
                <th th:text="${#dates.format(bill.billTime, 'yyyy-MM-dd')}">-</th>
                <th th:text="${bill.price}">-</th>
                <th th:text="${bill.billType!=null?bill.billType.name:'-'}">-</th>
                <th th:text="${bill.explain}">-</th>
                <th>
                    <a th:href="@{/bill/toUpdate(billId=${bill.id})}">更改</a>
                    <a th:href="@{/bill/delete(billId=${bill.id})}">删除</a>
                </th>
            </tr>
        </tbody>
    </table>
</div>
<ul class="pagination">
    <li><button class="btn btn-default" id="first-page-btn">首页</button></li>
    <li><button class="btn btn-default" id="pre-page-btn" th:disabled="${pageNum==1?'true':'false'}">上一页</button></li>
    <li><button class="btn btn-default" id="next-page-btn" th:disabled="${pageNum==pageCount?'true':'false'}">下一页</button></li>
    <li th:each="pn:${#numbers.sequence(1, pageCount)}">
        <button class="btn btn-default" th:text="${pn}" name="page-button" th:disabled="${pageNum==pn?'true':'false'}"></button>
    </li>
    <li><button class="btn btn-default" id="last-page-btn">尾页</button></li>
</ul>
<script type="text/javascript" th:inline="javascript">
    $(function(){


        $("#first-page-btn").click(function(){
            $("#page-num-input").val(1);
            $("#qf").submit();
        });

        $("#pre-page-btn").click(function(){
            $("#page-num-input").val([[${pageNum}]]-1);
            $("#qf").submit();
        });

        $("#next-page-btn").click(function(){
            $("#page-num-input").val([[${pageNum}]]+1);
            $("#qf").submit();
        });

        $("#last-page-btn").click(function(){
            $("#page-num-input").val([[${pageCount}]]);
            $("#qf").submit();
        });

        $("button[name='page-button']").click(function (){
            $("#page-num-input").val($(this).html());
            $("#qf").submit();
        });
    });
</script>
</body>
</html>